import 'package:flutter/material.dart';

import 'package:get/get.dart';

import '../controllers/button_controller.dart';

class ButtonView extends GetView<ButtonController> {
  _buildPopupMenuButton() {
    return PopupMenuButton(
      itemBuilder: (context) {
        return <PopupMenuEntry>[
          PopupMenuItem(
            child: Text("语文"),
            value: "语文",
          ),
          PopupMenuItem(
            child: Text("数学"),
            value: "数学",
          ),
          PopupMenuItem(
            child: Text("英语"),
            value: "英语",
          ),
          PopupMenuItem(
            child: Text("化学"),
            value: "化学",
          ),
          PopupMenuItem(
            child: Text("物理"),
            value: "物理",
          ),
        ];
      },
      onSelected: (val) {
        print("onSelected $val");
      },
      onCanceled: () {
        print("onCanceled");
      },
    );
  }

  _buildDropdownButton() {
    return Obx(() => DropdownButton<String>(
            value: controller.dropValue.value,
            onChanged: (val) {
              controller.updateDrop(val ?? "");
            },
            items: [
              DropdownMenuItem(
                child: Text("语文"),
                value: "语文",
              ),
              DropdownMenuItem(
                child: Text("数学"),
                value: "数学",
              ),
              DropdownMenuItem(
                child: Text("英语"),
                value: "英语",
              ),
            ]));
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('ButtonView'),
        centerTitle: true,
      ),
      body: Container(
        padding: EdgeInsets.all(15),
        child: Column(
          children: [
            _buildDropdownButton(),
            _buildPopupMenuButton(),
          ],
        ),
      ),
    );
  }
}
